package com.atguigu.map;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class MapTest1 {
    @Test
    public void test(){
        Map map=new HashMap();
        //添加 add()
        map.put("AA",123);
        map.put(45,123);
        map.put("bb",123);
        //修改
        map.put("AA",98);
        System.out.println(map);
        //putAll方法
        Map map1=new HashMap();
        map1.put("CC","DD");
        map1.putAll(map);
        System.out.println(map1);
        //remove(Object key):移除
        map1.remove("CC");
        System.out.println(map1);
        //clear()
        map.clear();//与map=null不同
    }
    @Test
    public void test2(){
        Map map=new HashMap();
        map.put("AA",123);
        map.put(45,123);
        map.put("BB",456);
        //Object get(Object key):获取key对应的value
        System.out.println(map.get(45)); //123
        //boolean containsKey(Object key):是否包含指定的key
        System.out.println(map.containsKey(45));
        //boolean containsValue(Object value):是否包含指定的value
        System.out.println(map.containsValue(123));
        //int size():返回map中key-value的对数
        System.out.println(map.size()); //3
        //boolean isEmpty():是否为空
        System.out.println(map.isEmpty()); //false
        //
    }
    @Test
    public void test3(){

    }
}
